/*
 * @Descripttion:
 * @Copyright: 武汉一一零七科技有限公司©版权所有
 * @Link: 1074699502@qq.com
 * @Contact: QQ:1074699502
 * @LastEditors: wzb
 * @LastEditTime: 2020-11-18 18:29:46
 */
export default {
    data(){
        return{
            baseUrl:uni.getStorageSync('baseUrl'),
            shareModel:false,  //分享遮罩层开启关闭
            shareImg: '',   //分海报
            shareTit: '',  //分标标题
            shareText: '',  //分享简介
            shareLink:''  //分链接
          }
    },
    methods:{
        // type  0:图文     1:纯文字   2:纯图片    3:音乐   4:视频   5:小程序
        // scene    WXSceneSession:分享到聊天界面      WXSenceTimeline:分享到朋友圈     WXSceneFavorite:分享到微信关注
        goShareApp(provider='weixin', scene='WXSceneSession',type) {
            this.$loading('拉取微信中...')
            uni.share({
                provider:provider,
                scene:scene,
                type:type,
                imageUrl:this.shareImg,

                success:res=>{
                    this.$toast('分享成功')
                },
                fail: err=> {
                    this.$toast(err)
                },
                complete:data=>{
                    this.$hideLoading()
                }
            });

        },
        copyShareLink(){
            uni.setClipboardData({
                data:this.shareLink ,
                success: ()=> {
                    this.$toast('复制成功')
                }
            })
        },

        //    分享链接
        shareWebLink(provider='weixin',scene='WXSceneSession',type=0){
            uni.share({
                provider:provider,
                scene: scene,
                type: type,
                href:this.shareLink,
                title:this.shareTit,
                summary: this.shareText,
                success: res=>{
                    this.$toast('分享成功')
                },
                fail:  err =>{
                    this.$toast(err)
                }
            });
        },
        removeHTMLTag(str) {
            str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
            str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
            //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
            str=str.replace(/ /ig,'');//去掉
            return str;
        },
        //多图分享
        multipleImgShare(list,copyText){

            this.$copy(this.removeHTMLTag(copyText));

            list.map((element,index) => {
                this.savaImgAlbum(element,index)
            });
            setTimeout(()=>{
                // #ifdef APP-PLUS

                plus.runtime.openURL('weixin://WXSceneTimeline');
                // #endif
            }, 1500);

        },
        // 系统分享
        otherShare(){
            uni.shareWithSystem({
                summary:this.shareText,
                href: this.shareLink,
                success(){
                    // 分享完成，请注意此时不一定是成功分享
                },
                fail(){
                    // 分享失败
                }
            })
        },

        savaImgAlbum(){
            console.log("-> ", this.shareImg );
            this.$loading('下载中...')
            uni.saveImageToPhotosAlbum({
                filePath: this.shareImg ,
                success: ()=> {
                        this.$toast('分享图片已成功保存到相册')
                }
            });
              setTimeout(()=>{

                this.$hideLoading()
            },1000)
        }
    }
}
